static-delta: Handle LZMA_BUF_ERROR returned by zlib
authorJohn Hiesey <john@hiesey.com>
Wed, 7 Oct 2015 20:30:33 +0000 (13:30 -0700)
committerColin Walters <walters@verbum.org>
Sat, 10 Oct 2015 14:27:17 +0000 (10:27 -0400)
zlib can return LZMA_BUF_ERROR, which indicates that either
the input or output buffer has size zero. This case should cause
the correct error to be passed back from g_converter_convert
to expand the relevant buffer. Since this error is ambiguous
as to which buffer is too small, an explicit check on the
output buffer size is added as well.

https://bugzilla.gnome.org/show_bug.cgi?id=756260

src/libostree/ostree-lzma-common.c
src/libostree/ostree-lzma-compressor.c
src/libostree/ostree-lzma-decompressor.c

index 3600efd339f19bf833c05083ed24e3d19a220fb4..61f3a2a471c33269a51ef5e45d4c20e1e27e880b 100644 (file)
@@ -62,6 +62,10 @@ _ostree_lzma_return (lzma_ret   res,
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Data is corrupt");
       return G_CONVERTER_ERROR;
+    case LZMA_BUF_ERROR:
+      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT,
+         "Input buffer too small");
+      return G_CONVERTER_ERROR;
     default:
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Unrecognized LZMA error");
index ce429f99f238a486a9b9fd436fe615e7ef6fc0ef..1ec03c41e03e7ec716265ce3f22ef3e66e6b2cbc 100644 (file)
@@ -173,6 +173,13 @@ _ostree_lzma_compressor_convert (GConverter *converter,
   int res;
   lzma_action action; 
 
+  if (inbuf_size != 0 && outbuf_size == 0)
+    {
+      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NO_SPACE,
+         "Output buffer too small");
+      return G_CONVERTER_ERROR;
+    }
+
   if (!self->initialized)
     {
       res = lzma_easy_encoder (&self->lstream, 8, LZMA_CHECK_CRC64);
index 51630132402b761521044a8966d7317de2f8b877..b46e8fb2c096ca2bc1361cc99e515db136c00c16 100644 (file)
@@ -104,6 +104,13 @@ _ostree_lzma_decompressor_convert (GConverter *converter,
   OstreeLzmaDecompressor *self = OSTREE_LZMA_DECOMPRESSOR (converter);
   int res;
 
+  if (inbuf_size != 0 && outbuf_size == 0)
+    {
+      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NO_SPACE,
+         "Output buffer too small");
+      return G_CONVERTER_ERROR;
+    }
+
   if (!self->initialized)
     {
       res = lzma_stream_decoder (&self->lstream, G_MAXUINT64, 0);